package org.come.Frame;

import com.tool.tcpimg.UIUtils;
import org.come.Jpanel.DianJpanel;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;

import javax.swing.*;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class DdianJframe extends JInternalFrame implements MouseListener {
    private DianJpanel dianJpanel;
    private int first_x, first_y;// x、y坐标
    public static DdianJframe getDdianJframe(){
        return (DdianJframe) FormsManagement.getInternalForm(120).getFrame();

    }
    public DdianJframe() throws Exception{
        dianJpanel=new DianJpanel();
        this.getContentPane().add(dianJpanel);
        this.setBorder(BorderFactory.createEmptyBorder());// 去除内部窗体的边框
        ((BasicInternalFrameUI) this.getUI()).setNorthPane(null);// 去除顶部的边框

        this.setBounds(200, 100, 470, 315);// 设置窗口出现的位置
        this.pack();
        this.setVisible(false);
        this.setBackground(UIUtils.Color_BACK);
        this.addMouseListener(this);
        this.addMouseMotionListener(new MouseMotionListener() {// 判断窗口移动的位置

            @Override
            public void mouseMoved(MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                if (isVisible()) {
                    int x = e.getX() - first_x;
                    int y = e.getY() - first_y;
                    DdianJframe.this.setBounds(x + DdianJframe.this.getX(), y + DdianJframe.this.getY(), DdianJframe.this.getWidth(), DdianJframe.this.getHeight());
                }
            }
        });

    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        Music.addyinxiao("关闭窗口.mp3");
        if (e.isMetaDown()) {// 检测鼠标右键单击

            // 清空选中的内丹


            FormsManagement.HideForm(120);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    public DianJpanel getDianJpanel() {
        return dianJpanel;
    }

    public void setDianJpanel(DianJpanel dianJpanel) {
        this.dianJpanel = dianJpanel;
    }

    public int getFirst_x() {
        return first_x;
    }

    public void setFirst_x(int first_x) {
        this.first_x = first_x;
    }

    public int getFirst_y() {
        return first_y;
    }

    public void setFirst_y(int first_y) {
        this.first_y = first_y;
    }
}
